﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class SendProductRequisition : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindApplicationInfo();
            }
        }

        private void BindApplicationInfo()
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm form = service.GetApplicationFormDetailByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            numberLabel.Text = form.RequisitionForm.ID.ToString();
            dateLabel.Text = DateTime.Now.ToString("yyyy-MM-dd");
            rmacodeLabel.Text = form.ApplicationCode;
            connectPersonLabel.Text = form.User.UserName;
            clientComanyTextBox.Text = form.User.CompanyName;
            phoneLabel.Text = form.User.UserPhone;
            addressLabel.Text = form.User.UserAddress;
            productGridView.DataSource = form.ApplicationProduct;
            productGridView.DataBind();
        }

        protected void saveButton_Click(object sender, EventArgs e)
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm form = service.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if(!form.RequisitionFormReference.IsLoaded)
            {
                form.RequisitionFormReference.Load();
            }
            form.RequisitionForm.RequisitionPerson = personTextBox.Text;
            form.RequisitionForm.WayOfTransport = wayDropDownList.SelectedValue;
            form.RequisitionForm.DistributionCompany = wlgsTextBox.Text;
            form.RequisitionForm.DistributionFormID = distributeIDTextBox.Text;
            form.Status = "已发货待客户确认";
            service.UpdateApplication(form);
        }
    }
}
